﻿///<reference path="../../vswd-ext_2.0.2.js" />
Ext.BLANK_IMAGE_URL = '../../Images/s.gif';

//用户
var userDs = new Ext.data.Store({
    url: '../../Trans/Base/User.aspx',
    baseParams: {
        action: 'list',
        search_params: '' //查询参数
    },
    remoteSort: true,
    reader: new Ext.data.JsonReader({
        root: 'rows',
        totalProperty: 'rowsCount'
    },[
        'UserId',
        'UserName',
        'Password',
        'RealName',
        'Role',
        'Sex',
        'IdNumber',
        'MobilePhone',
        'Phone',
        'SortIndex',
        'CreateTime',
        'UpdateTime'
    ])
});

//性别 
var sexDs = new Ext.data.Store({
    url: '../../Trans/Base/Arg.aspx',
    baseParams: {
        action: 'arg',
        arg_type: EF.UI.Const.ArgTypeMark.SEX
    },
    reader: new Ext.data.JsonReader({
        root: 'rows'
    },[
        'ArgId',
        'ArgName'
    ])
});

//角色
var roleDs = new Ext.data.Store({
    url: '../../Trans/Base/Role.aspx',
    baseParams: {
        action: 'short_list'
    },
    reader: new Ext.data.JsonReader({
        root: 'rows'
    },[
        'RoleId',
        'RoleName'
    ])
});

Ext.onReady(function(){
    Ext.QuickTips.init();
    
    var urlArgObj = Ext.urlDecode(window.location.search.substring(1, window.location.search.length));
    var tabHeight = urlArgObj['h']-1; //the height of tab panel
    var tabWidth = urlArgObj['w']-1; //the width of tab panel
    var pageId = urlArgObj['page_id']; //the function id of the page
    
    Ext.Ajax.request({
        url: '../../Trans/Base/Lang.aspx',
        params: {
            action: 'lang',
            marks: "'grid_panel_display_msg','grid_panel_empt_msg','col_user_name','col_password','col_real_name','col_role','col_sex','col_id_number','col_mobile_phone','col_phone','col_sort_index','col_create_time','col_update_time','title_add','lbl_user_name','lbl_password','lbl_real_name','lbl_sex','lbl_id_number','lbl_mobile_phone','lbl_phone','btn_save','btn_close','combo_empty_text','max_length_text','blank_text','title_tip','btn_sure','lbl_role','msg_invalid_id_number','msg_invalid_mobile_phone','msg_invalid_phone','msg_select_one_to_eidt','title_edit','msg_select_one_to_view','title_view','msg_select_one_to_del','msg_confirm_to_del','btn_cancel','btn_search','title_search','title_history','btn_restore','msg_select_records_to_restore'"
        },
        success: function(response, opts) {
            var langObj = Ext.decode(response.responseText);
            langObj = langObj['rows'][0];
            
            //加载数据
            userDs.load();
            sexDs.load();
            roleDs.load();
            
            //用户表单 begin
            
            //身份证号码验证
            Ext.form.VTypes['IdNumberVal'] = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
            Ext.form.VTypes['IdNumberText'] = langObj ['msg_invalid_id_number'];
            Ext.form.VTypes['IdNumber'] = function(v) {
                if (v != '') {
                    return Ext.form.VTypes['IdNumberVal'].test(v);
                }
                return true;
            }; 
            
            //手机号码验证
            Ext.form.VTypes['MobilePhoneVal'] = /^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/;
            Ext.form.VTypes['MobilePhoneText'] = langObj ['msg_invalid_mobile_phone'];
            Ext.form.VTypes['MobilePhone'] = function(v) {
                if (v !=  '') {
                    return Ext.form.VTypes['MobilePhoneVal'].test(v);
                }
                return true;
            };
            
            //电话号码验证
            Ext.form.VTypes['PhoneVal'] = /(^(\d{2,4}[-_－—]?)?\d{3,8}([-_－—]?\d{3,8})?([-_－—]?\d{1,7})?$)|(^0?1[35] \d{9}$)/;
            Ext.form.VTypes['PhoneText'] = langObj ['msg_invalid_phone'];
            Ext.form.VTypes['Phone'] = function(v) {
                if (v !=  '') {
                    return Ext.form.VTypes['PhoneVal'].test(v);
                }
                return true;
            };
            
            var p1 = new Ext.Panel({
                    layout: 'column',
                    border: false,
                    width: 440,
                    bodyStyle: 'padding:5px 5px 0;background:transparent;',
                    items: [{
                        xtype: 'panel',
                        width: 200,
                        layout: 'form',
                        border: false,
                        bodyStyle: 'padding:5px 5px 0;background:transparent;',
                        items: [{
                            xtype: 'hidden',
                            name: 'UserId'
                        },{
                            xtype: 'textfield',
                            width: 100,
                            name: 'UserName',
                            fieldLabel: langObj['lbl_user_name'],
                            maxLength: 10,
                            maxLengthText: langObj['max_length_text'],
                            allowBlank: false,
                            blankText: langObj['blank_text']
                        },{
                            xtype: 'textfield',
                            width: 100,
                            name: 'RealName',
                            fieldLabel: langObj['lbl_real_name'],
                            maxLength: 10,
                            maxLengthText: langObj['max_length_text'],
                            allowBlank: false,
                            blankText: langObj['blank_text']
                        },{
                            xtype: 'textfield',
                            width: 100,
                            name: 'IdNumber',
                            fieldLabel: langObj['lbl_id_number'],
                            maxLength: 20,
                            maxLengthText: langObj['max_length_text'],
                            vtype: 'IdNumber'
                        },{
                            xtype: 'textfield',
                            width: 100,
                            name: 'Phone',
                            fieldLabel: langObj['lbl_phone'],
                            maxLength: 8,
                            maxLengthText: langObj['max_length_text'],
                            vtype: 'Phone'
                        }]
                    },{
                        xtype: 'panel',
                        width: 200,
                        layout: 'form',
                        border: false,
                        bodyStyle: 'padding:5px 5px 0;background:transparent;',
                        items: [{
                            xtype: 'textfield',
                            width: 100,
                            name: 'Password',
                            fieldLabel: langObj['lbl_password'],
                            maxLength: 6,
                            maxLengthText: langObj['max_length_text'],
                            allowBlank: false,
                            blankText: langObj['blank_text']
                        },{
                            xtype: 'combo',
                            store: roleDs,
                            name: 'Role',
                            displayField: 'RoleName',
                            valueField: 'RoleId',
                            forceSelection: true,
                            width: 100,
                            mode: 'local',
                            fieldLabel: langObj['lbl_role'],
                            emptyText: langObj['combo_empty_text'],
                            triggerAction: 'all',
                            allowBlank: false,
                            blankText: langObj['blank_text']
                        },{
                            xtype: 'combo',
                            store: sexDs,
                            name: 'Sex',
                            displayField: 'ArgName',
                            valueField: 'ArgId',
                            forceSelection: true,
                            width: 100,
                            mode: 'local',
                            fieldLabel: langObj['lbl_sex'],
                            emptyText: langObj['combo_empty_text'],
                            triggerAction: 'all'
                        },{
                            xtype: 'textfield',
                            width: 100,
                            name: 'MobilePhone',
                            fieldLabel: langObj['lbl_mobile_phone'],
                            maxLength: 11,
                            maxLengthText: langObj['max_length_text'],
                            vtype: 'MobilePhone',
                            allowBlank: false,
                            blankText: langObj['blank_text']
                        }]
                    }]
                });
                
                var action = null; //操作
                
                var userFormPanel = new Ext.FormPanel({
                    id: 'userForm',
                    border: false,
                    width: 440,
                    labelWidth: 80,
                    labelAlign: 'right',
                    buttonAlign: 'center',
                    bodyStyle: 'padding:5px 5px 0;background:transparent;',
                    items: [p1],
                    buttons: [{
                        id: 'btn_save',
                        text: langObj['btn_save'],
                        width: 60,
                        handler: function() {
                            var userForm = userFormPanel.getForm();
                            if (userForm.isValid()) {
                                win.hide(null, function(){
                                    var model = '{';
                                    model += "'UserName':'" + userForm.findField('UserName').getValue() + "',";
                                    model += "'Password':'" + userForm.findField('Password').getValue() + "',";
                                    model += "'Role':'" + userForm.findField('Role').getValue() + "',";
                                    
                                    if (userForm.findField('UserId').getValue() != '') {
                                        model += "'UserId':'" + userForm.findField('UserId').getValue() + "',";
                                    }
                                    if (userForm.findField('IdNumber').getValue() != '') {
                                        model += "'IdNumber':'" + userForm.findField('IdNumber').getValue() + "',";
                                    }
                                    if (userForm.findField('Phone').getValue() != '') {
                                        model += "'Phone':'" + userForm.findField('Phone').getValue() + "',";
                                    }
                                    if (userForm.findField('Sex').getValue() != null && userForm.findField('Sex').getValue() != '0') {
                                        model += "'Sex':'" + userForm.findField('Sex').getValue() + "',";
                                    }
                                    if (userForm.findField('MobilePhone').getValue() != '') {
                                        model += "'MobilePhone':'" + userForm.findField('MobilePhone').getValue() + "',";
                                    }
                                    model += "'RealName':'" + userForm.findField('RealName').getValue() + "'}";
                                    
                                    Ext.Ajax.request({
                                        url: '../../Trans/Base/User.aspx',
                                        params: {
                                            action: action,
                                            model: model
                                        },
                                        success: function(response, opts) {
                                            var obj = Ext.decode(response.responseText);
                                            
                                            if (obj['success'] == true) {
                                                Ext.Msg.show({
                                                    title: langObj['title_tip'],
                                                    msg: obj['msg'],
                                                    buttons: {yes: langObj['btn_sure']},
                                                    icon: Ext.MessageBox.INFO
                                                });
                                                
                                                userDs.reload();
                                            } else {
                                                Ext.Msg.show({
                                                    title: langObj['title_tip'],
                                                    msg: obj['msg'],
                                                    buttons: {yes: langObj['btn_sure']},
                                                    icon: Ext.MessageBox.ERROR
                                                });
                                            }
                                        },
                                        failure: function(response, opts) {
                                            var obj = Ext.decode(response.responseText);
                                            Ext.Msg.show({
                                                title: langObj['title_tip'],
                                                msg: obj['msg'],
                                                buttons: {yes: langObj['btn_sure']},
                                                icon: Ext.MessageBox.ERROR
                                            });
                                        }
                                    });
                                },this);
                            }
                        }
                    },{
                        text: langObj['btn_close'],
                        width: 60,
                        handler: function() {
                            win.hide(null, null, this);
                        }
                    }]
                });
                
                //显示窗体
                var win = new Ext.Window({
                    modal: true,
                    resizable: false,
                    closable: false,
                    width: 450,
                    height: 200,
                    items: [userFormPanel]
                });
                
            //用户表单 end
            
            //给用户表单设置初始值
            function userFormSetDefault() {
                var userForm = userFormPanel.getForm();
                
                userForm.items.each(function(item, index, lenght) {
                    item.enable();
                    
                    if (item.getXType() == 'combo') {
                        item.setRawValue(langObj['combo_empty_text']);
                    } else {
                        item.setRawValue();
                    }
                }, this);
                
                userFormPanel.getFooterToolbar().findById('btn_save').enable(); //激活保存按钮
            }
            
            //刷新
            function userRefresh() {
                userDs.setBaseParam('search_params', ''); //清空查询参数
                userDs.load();
            }

            //新建
            function userAdd() {
                userFormSetDefault();
                userDs.setBaseParam('search_params', '');
                action = 'add';
                win.setTitle(langObj['title_add']);
                win.show(null,null,this);
            }

            //编辑
            function userEdit() {
                if (checkboxSel.hasSelection()) {
                    var selections = checkboxSel.getSelections();
                    if (selections.length > 1) {
                        Ext.Msg.show({
                            title: langObj['title_tip'],
                            msg: langObj['msg_select_one_to_eidt'],
                            buttons: {yes: langObj['btn_sure']},
                            icon: Ext.MessageBox.INFO
                        });
                    } else {
                        Ext.Ajax.request({
                            url: '../../Trans/Base/User.aspx',
                            params: {
                                action: 'model',
                                sel_user_id: selections[0].data.UserId
                            },
                            success: function(response, opts) {
                                var obj = Ext.decode(response.responseText);
                                if (obj['success'] == true) {
                                    var userModel = obj['rows'];
                                    
                                    userFormSetDefault();
                                    action = 'edit';
                                    
                                    var userForm = userFormPanel.getForm();
                                    userForm.findField('UserName').setValue(userModel['UserName']);
                                    userForm.findField('UserName').disable();
                                    userForm.findField('Password').setValue(userModel['Password']);
                                    userForm.findField('Role').setValue(userModel['Role']);
                                    userForm.findField('UserId').setValue(userModel['UserId']);
                                    userForm.findField('IdNumber').setValue(userModel['IdNumber']);
                                    userForm.findField('Phone').setValue(userModel['Phone']);
                                    userForm.findField('Sex').setValue(userModel['Sex']);
                                    userForm.findField('MobilePhone').setValue(userModel['MobilePhone']);
                                    userForm.findField('RealName').setValue(userModel['RealName']);
                                    
                                    win.setTitle(langObj['title_edit']);
                                    win.show(null,null,this);
                                } else {
                                    Ext.Msg.show({
                                        title: langObj['title_tip'],
                                        msg: obj['msg'],
                                        buttons: {yes: langObj['btn_sure']},
                                        icon: Ext.MessageBox.ERROR
                                    });
                                }
                            },
                            failure: function(response, opts) {
                                var obj = Ext.decode(response.responseText);
                                Ext.Msg.show({
                                    title: langObj['title_tip'],
                                    msg: obj['msg'],
                                    buttons: {yes: langObj['btn_sure']},
                                    icon: Ext.MessageBox.ERROR
                                });
                            }
                        });
                    }
                } else {
                    Ext.Msg.show({
                        title: langObj['title_tip'],
                        msg: langObj['msg_select_one_to_eidt'],
                        buttons: {yes: langObj['btn_sure']},
                        icon: Ext.MessageBox.INFO
                    });
                }
            }

            //查看
            function userView() {
                if (checkboxSel.hasSelection()) {
                    var selections = checkboxSel.getSelections();
                    if (selections.length > 1) {
                        Ext.Msg.show({
                            title: langObj['title_tip'],
                            msg: langObj['msg_select_one_to_view'],
                            buttons: {yes: langObj['btn_sure']},
                            icon: Ext.MessageBox.INFO
                        });
                    } else {
                        Ext.Ajax.request({
                            url: '../../Trans/Base/User.aspx',
                            params: {
                                action: 'model',
                                sel_user_id: selections[0].data.UserId
                            },
                            success: function(response, opts) {
                                var obj = Ext.decode(response.responseText);
                                if (obj['success'] == true) {
                                    var userModel = obj['rows'];
                                    
                                    userFormSetDefault();
                                    
                                    var userForm = userFormPanel.getForm();
                                    
                                    userForm.items.each(function(item, index, lenght) {
                                        item.disable();
                                    },this);
                                    
                                    userForm.findField('UserName').setValue(userModel['UserName']);
                                    userForm.findField('Password').setValue(userModel['Password']);
                                    userForm.findField('Role').setValue(userModel['Role']);
                                    userForm.findField('UserId').setValue(userModel['UserId']);
                                    userForm.findField('IdNumber').setValue(userModel['IdNumber']);
                                    userForm.findField('Phone').setValue(userModel['Phone']);
                                    userForm.findField('Sex').setValue(userModel['Sex']);
                                    userForm.findField('MobilePhone').setValue(userModel['MobilePhone']);
                                    userForm.findField('RealName').setValue(userModel['RealName']);
                                    
                                    userFormPanel.getFooterToolbar().findById('btn_save').disable(); //禁止保存按钮
                                    
                                    win.setTitle(langObj['title_view']);
                                    win.show(null,null,this);
                                } else {
                                    Ext.Msg.show({
                                        title: langObj['title_tip'],
                                        msg: obj['msg'],
                                        buttons: {yes: langObj['btn_sure']},
                                        icon: Ext.MessageBox.ERROR
                                    });
                                }
                            },
                            failure: function(response, opts) {
                                var obj = Ext.decode(response.responseText);
                                Ext.Msg.show({
                                    title: langObj['title_tip'],
                                    msg: obj['msg'],
                                    buttons: {yes: langObj['btn_sure']},
                                    icon: Ext.MessageBox.ERROR
                                });
                            }
                        });
                    }
                } else {
                    Ext.Msg.show({
                        title: langObj['title_tip'],
                        msg: langObj['msg_select_one_to_view'],
                        buttons: {yes: langObj['btn_sure']},
                        icon: Ext.MessageBox.INFO
                    });
                }
            }

            //查看历史用户
            function userHistory() {
                var userHistoryDs = new Ext.data.Store({
                    url: '../../Trans/Base/User.aspx',
                    baseParams: {
                        action: 'history'
                    },
                    remoteSort: true,
                    reader: new Ext.data.JsonReader({
                        root: 'rows',
                        totalProperty: 'rowsCount'
                    },[
                        'UserId',
                        'UserName',
                        'Password',
                        'RealName',
                        'Role',
                        'Sex',
                        'IdNumber',
                        'MobilePhone',
                        'Phone',
                        'SortIndex',
                        'CreateTime',
                        'UpdateTime'
                    ])
                });
                userHistoryDs.load();
                
                var checkboxSel = new Ext.grid.CheckboxSelectionModel();
            
                var userHistoryGrid = new Ext.grid.GridPanel({
                    id: 'userHistoryGrid',
                    frame: false,
                    height: 400,
                    store: userHistoryDs,
                    loadMask: true,
                    sm: checkboxSel,
                    tbar: [{
                        text: langObj['btn_restore'],
                        width: 60,
                        handler: function() {
                            if (checkboxSel.hasSelection()) {
                                var selections = checkboxSel.getSelections();
                                
                                var selUserIds = "";
                                for (var i = 0; i < selections.length; i++) {
                                    selUserIds += selections[i].data.UserId.toString() + ",";
                                }
                                selUserIds = selUserIds.substring(0, selUserIds.length - 1);
                                
                                Ext.Ajax.request({
                                    url: '../../Trans/Base/User.aspx',
                                    params: {
                                        action: 'restore',
                                        sel_user_id: selUserIds
                                    },
                                    success: function(response, opts) {
                                        var obj = Ext.decode(response.responseText);
                                        if (obj['success'] == true) {
                                            userDs.reload();
                                            userHistoryDs.reload();
                                            
                                        }
                                        
                                        Ext.Msg.show({
                                            title: langObj['title_tip'],
                                            msg: obj['msg'],
                                            buttons: {yes: langObj['btn_sure']},
                                            icon: Ext.MessageBox.INFO
                                        });
                                    },
                                    failure: function(response, opts) {
                                        var obj = Ext.decode(response.responseText);
                                        Ext.Msg.show({
                                            title: langObj['title_tip'],
                                            msg: obj['msg'],
                                            buttons: {yes: langObj['btn_sure']},
                                            icon: Ext.MessageBox.ERROR
                                        });
                                    }
                                });
                                
                            } else {
                                Ext.Msg.show({
                                    title: langObj['title_tip'],
                                    msg: langObj['msg_select_records_to_restore'],
                                    buttons: {yes: langObj['btn_sure']},
                                    icon: Ext.MessageBox.INFO
                                });
                            }
                        }
                    }],
                    bbar: new Ext.PagingToolbar({
                        pageSize: EF.UI.Const.PageConfig.PAGESIZE,
                        store: userHistoryDs,
                        displayInfo: true,
                        displayMsg: langObj['grid_panel_display_msg'],
                        emptMsg: langObj['grid_panel_empt_msg']
                    }),
                    columns: [new Ext.grid.RowNumberer(),checkboxSel,{
                        header: 'UserId',
                        dataIndex: 'UserId',
                        hidden: true,
                        sortable: true,
                        menuDisabled: true
                    },{
                        header: langObj['col_user_name'],
                        dataIndex: 'UserName',
                        sortable: true,
                        width: 80
                    },{
                        header: langObj['col_real_name'],
                        dataIndex: 'RealName',
                        sortable: true,
                        width: 80
                    },{
                        header: langObj['col_role'],
                        dataIndex: 'Role',
                        sortable: true,
                        width: 100
                    },{
                        header: langObj['col_create_time'],
                        dataIndex: 'CreateTime',
                        sortable: true,
                        width: 130
                    },{
                        header: langObj['col_update_time'],
                        dataIndex: 'UpdateTime',
                        sortable: true,
                        width: 130
                    }]
                });
                
                //显示窗体
                var win = new Ext.Window({
                    title: langObj['title_history'],
                    modal: true,
                    resizable: true,
                    closable: false,
                    width: 630,
                    height: 465,
                    buttonAlign: 'center',
                    items: [userHistoryGrid],
                    buttons: [{
                        text: langObj['btn_close'],
                        width: 60,
                        
                        handler: function() {
                            win.hide(null, null, this);
                        }
                    }]
                }); 
                
                win.show(null, null, this);
            }
            
            //搜索
            function userSearch() {
                var userSearchFP = new Ext.FormPanel({
                    id: 'userSearchForm',
                    border: false,
                    width: 260,
                    labelWidth: 80,
                    labelAlign: 'right',
                    buttonAlign: 'center',
                    bodyStyle: 'padding:5px 5px 0;background:transparent;',
                    items: [{
                         xtype: 'textfield',
                         width: 100,
                         name: 'UserName',
                         fieldLabel: langObj['lbl_user_name'],
                         maxLength: 10,
                         maxLengthText: langObj['max_length_text']
                    },{
                         xtype: 'combo',
                         store: roleDs,
                         name: 'Role',
                         displayField: 'RoleName',
                         valueField: 'RoleId',
                         forceSelection: true,
                         width: 100,
                         mode: 'local',
                         fieldLabel: langObj['lbl_role'],
                         emptyText: langObj['combo_empty_text'],
                         triggerAction: 'all'
                    }],
                    buttons: [{
                        text: langObj['btn_search'],
                        width: 60,
                        handler: function() {
                            var userSearchForm = userSearchFP.getForm();
                            if (userSearchForm.isValid()) {
                                win.hide(null, function(){
                                    
                                    var searchParams = "["
                                    
                                    if (userSearchForm.findField('UserName').getValue() != '') {
                                        searchParams += "{Name:'userName',Value:'" + userSearchForm.findField('UserName').getValue() + "'},";
                                    }
                                    if (userSearchForm.findField('Role').getValue() != '' && userSearchForm.findField('Role').getValue() != '0') {
                                        searchParams += "{Name:'role',Value:'" + userSearchForm.findField('Role').getValue() + "'},";
                                    }
                                    searchParams = searchParams.substring(0, searchParams.length - 1)
                                    searchParams += ']';
                                    
                                    if (searchParams.length <= 1) {
                                        userDs.setBaseParam('search_params', ''); 
                                    } else {
                                        userDs.setBaseParam('search_params', searchParams);
                                    }
                                    
                                    userDs.load();
                                },this);
                            }
                        }
                    },{
                        text: langObj['btn_close'],
                        width: 60,
                        handler: function() {
                            win.hide(null, null, this);
                        }
                    }]
                });
                
                //显示窗体
                var win = new Ext.Window({
                    title: langObj['title_search'],
                    modal: true,
                    resizable: false,
                    closable: false,
                    width: 260,
                    height: 130,
                    items: [userSearchFP]
                }); 
                
                win.show(null, null, this);
            }

            //逻辑删除
            function userLogicDel() {
                if (checkboxSel.hasSelection()) {
                    Ext.Msg.show({
                        title: langObj['title_tip'],
                        msg: langObj['msg_confirm_to_del'],
                        buttons: {yes: langObj['btn_sure'], no: langObj ['btn_cancel']},
                        icon: Ext.MessageBox.QUESTION,
                        fn: function(button, text) {
                            if (button == 'yes') {
                                var selections = checkboxSel.getSelections();
                    
                                var selUserIds = "";
                                for (var i = 0; i < selections.length; i++) {
                                    selUserIds += selections[i].data.UserId.toString() + ",";
                                }
                                selUserIds = selUserIds.substring(0, selUserIds.length - 1);
                                
                                Ext.Ajax.request({
                                    url: '../../Trans/Base/User.aspx',
                                    params: {
                                        action: 'logicdel',
                                        sel_user_id: selUserIds
                                    },
                                    success: function(response, opts) {
                                        var obj = Ext.decode(response.responseText);
                                        if (obj['success'] == true) {
                                            Ext.Msg.show({
                                                title: langObj['title_tip'],
                                                msg: obj['msg'],
                                                buttons: {yes: langObj['btn_sure']},
                                                icon: Ext.MessageBox.INFO
                                            });
                                            
                                            userDs.reload();
                                        } else {
                                            Ext.Msg.show({
                                                title: langObj['title_tip'],
                                                msg: obj['msg'],
                                                buttons: {yes: langObj['btn_sure']},
                                                icon: Ext.MessageBox.ERROR
                                            });
                                        }
                                    },
                                    failure: function(response, opts) {
                                        var obj = Ext.decode(response.responseText);
                                        Ext.Msg.show({
                                            title: langObj['title_tip'],
                                            msg: obj['msg'],
                                            buttons: {yes: langObj['btn_sure']},
                                            icon: Ext.MessageBox.ERROR
                                        });
                                    }
                                });
                            }
                        }
                    });
                    
                } else {
                    Ext.Msg.show({
                        title: langObj['title_tip'],
                        msg: langObj['msg_select_one_to_del'],
                        buttons: {yes: langObj['btn_sure']},
                        icon: Ext.MessageBox.INFO
                    });
                }
            }
            
            //导出
            function userExport() {
                var userColumnModel = userGrid.getColumnModel();
                
                //导出未隐藏的列
                var exportCols = "";
                var exportColNames = "";
                for (var i = 2; i < userColumnModel.getColumnCount(); i++) {
                    if (!userColumnModel.isHidden(i)) {
                        exportCols += userColumnModel.getDataIndex(i) + ",";
                        exportColNames += userColumnModel.getColumnHeader(i) + ",";
                    }
                }
                
                exportCols = exportCols.substring(0, exportCols.length - 1); //导出列索引
                exportColNames = exportColNames.substring(0, exportColNames.length - 1); //导出列名
                
                window.location.href = '../../Trans/Base/User.aspx?action=export&cols=' +  exportCols + '&col_names=' + exportColNames + '&search_params=' + userDs.baseParams['search_params'];
            }
            
            var checkboxSel = new Ext.grid.CheckboxSelectionModel();
            
            var userGrid = new Ext.grid.GridPanel({
                id: 'userGrid',
                renderTo: document.body,
                frame: false,
                height: tabHeight,
                store: userDs,
                loadMask: true,
                sm: checkboxSel,
                bbar: new Ext.PagingToolbar({
                    pageSize: EF.UI.Const.PageConfig.PAGESIZE,
                    store: userDs,
                    displayInfo: true,
                    displayMsg: langObj['grid_panel_display_msg'],
                    emptMsg: langObj['grid_panel_empt_msg']
                }),
                columns: [new Ext.grid.RowNumberer(),checkboxSel,{
                    header: 'UserId',
                    dataIndex: 'UserId',
                    hidden: true,
                    sortable: true,
                    menuDisabled: true
                },{
                    header: langObj['col_user_name'],
                    dataIndex: 'UserName',
                    sortable: true,
                    width: 80
                },{
                    header: langObj['col_password'],
                    dataIndex: 'Password',
                    sortable: true,
                    width: 80
                },{
                    header: langObj['col_real_name'],
                    dataIndex: 'RealName',
                    sortable: true,
                    width: 80
                },{
                    header: langObj['col_role'],
                    dataIndex: 'Role',
                    sortable: true,
                    width: 100
                },{
                    header: langObj['col_sex'],
                    dataIndex: 'Sex',
                    sortable: true,
                    width: 50
                },{
                    header: langObj['col_id_number'],
                    dataIndex: 'IdNumber',
                    sortable: true,
                    width: 130
                },{
                    header: langObj['col_mobile_phone'],
                    dataIndex: 'MobilePhone',
                    sortable: true,
                    width: 100
                },{
                    header: langObj['col_phone'],
                    dataIndex: 'Phone',
                    sortable: true,
                    width: 100
                },{
                    header: langObj['col_sort_index'],
                    dataIndex: 'SortIndex',
                    sortable: true,
                    width: 50
                },{
                    header: langObj['col_create_time'],
                    dataIndex: 'CreateTime',
                    sortable: true,
                    width: 130
                },{
                    header: langObj['col_update_time'],
                    dataIndex: 'UpdateTime',
                    sortable: true,
                    width: 130
                }]
            });
            
            //生成功能点
            Ext.Ajax.request({
                url: '../../Trans/Base/Function.aspx',
                params: {
                    action: 'func_points',
                    page_id: pageId
                },
                success: function(response, opts) {
                    var obj = Ext.decode(response.responseText);
                    
                    if (obj['success'] == true) {
                        var funcPointsObj = obj['rows'];
                        var tb = new Ext.Toolbar();
                        for (var propName in funcPointsObj) {
                            switch (propName) {
                                case EF.UI.Const.FuncPoints.REFRESH:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userRefresh
                                    });
                                break;
                                case EF.UI.Const.FuncPoints.ADD:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userAdd
                                    });
                                break; 
                                case EF.UI.Const.FuncPoints.EDIT:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userEdit
                                    });
                                break;
                                case EF.UI.Const.FuncPoints.VIEW:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userView
                                    });
                                break;
                                case EF.UI.Const.FuncPoints.SEARCH:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userSearch
                                    });
                                break;
                                case EF.UI.Const.FuncPoints.HISTORY:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userHistory
                                    });
                                break;
                                case EF.UI.Const.FuncPoints.LOGICDEL:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userLogicDel
                                    });
                                break;
                                case EF.UI.Const.FuncPoints.EXPORT:
                                    tb.add({
                                        text: funcPointsObj[propName],
                                        width: 60,
                                        handler: userExport
                                    });
                                break;
                            }
                        }
                        
                        userGrid.add(tb);
                        userGrid.doLayout();
                    }
                },
                failure: function(response, opts) {

                }
            });
            
            
            
        },
        failure: function() {
        
        }
    }); 
});